{extend name="base/form" /}
{block name="title"} 首页 {/block}
<!-- Page Content -->
{block name="content"}
<form class="layui-form">
    <input type="hidden" name="id" value="{$data.id}">
    <div class="layui-form-item">
        <label class="layui-form-label">标&nbsp;&nbsp;&nbsp;题</label>
        <div class="layui-input-block">
            <input type="text" id="title"  name="title" value="{$data.title}"  autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">下载地址</label>
        <div class="layui-input-block">
            <input type="text" id="down_url" value="{$data.down_url}"  name="down_url"  autocomplete="off" placeholder="请输入下载地址" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">平&nbsp;&nbsp;&nbsp;台</label>
        <div class="layui-input-block">
            <input type="radio" name="type" {eq name="data.type" value="1"} checked {/eq} value="1" title="安卓">
            <input type="radio" name="type" {eq name="data.type" value="2"} checked {/eq} value="2" title="iOS" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备&nbsp;&nbsp;&nbsp;注</label>
        <div class="layui-input-block">
            <textarea name="remark" placeholder="请输入备注" class="layui-textarea">{$data.remark}</textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button style="margin-left: 20%" class="layui-btn" lay-submit="*" lay-filter="addSubmit">提交</button>
            <button id="reset" type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>


</form>
<!-- /Page Content -->
{/block}
{block name="js"}
<script>
    layui.use(['form','layer'], function(){
        var $ = layui.jquery
            ,layer = layui.layer
            ,form =  layui.form

        //当你在iframe页面关闭自身时
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        //监听提交
        form.on('submit(addSubmit)', function(data){
            console.log(data.field)
            $.ajax({
                url:"{:url('editPost')}",
                type:'post',
                data:data.field,
                success:function(e){
                    if(e.code == 1){
                        layer.msg(e.msg,{icon:6,time:2000},function (){
                            parent.layer.close(index); //再执行关闭
                            window.location.reload()
                        })
                    }else{
                        layer.msg(e.msg,{icon:5,time:2000},function (){
                            parent.layer.close(index); //再执行关闭
                            window.location.reload()
                        })
                    }
                }
            });
            return false;
        });
    });
</script>
{/block}